package com.dreamer.domain.mall.transfer;

import com.dreamer.domain.user.Agent;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class AgentVo {

    private String name;

    private Double amount;


    private List<VoucherVo> voucherVos;

    private List<TransferVo> transferVos;

    private List<SumVo> sumVos;

    public static List<AgentVo> toAgentVo(List<TransferVo> transferVos,Integer type) {
        Map<String, List<TransferVo>> resultMap = new HashMap<>();
        transferVos.forEach(transferVo -> {
            String c;
            if (transferVo.getAdd() == 1) {
                c = transferVo.getToUser();
            } else {
                c = transferVo.getFromUser();
            }
            List<TransferVo> tems = new ArrayList<>();
            if (resultMap.containsKey(c)) {
                tems = resultMap.get(c);
            }
            tems.add(transferVo);
            resultMap.put(c, tems);
        });
        List<AgentVo> agentVos = new ArrayList<>();
        resultMap.forEach((k,v)->{
            AgentVo agentVo = new AgentVo();
            agentVo.setName(k);
            //统计奖金
            List<VoucherVo> voucherVos = VoucherVo.countFromTransferVos(v,type);
            agentVo.setVoucherVos(voucherVos);
            agentVo.setTransferVos(v);
            List<SumVo> sumVos = SumVo.sum(v);
            agentVo.setSumVos(sumVos);
            agentVos.add(agentVo);
        });
        return agentVos;
    }



    public List<VoucherVo> getVoucherVos() {
        return voucherVos;
    }

    public void setVoucherVos(List<VoucherVo> voucherVos) {
        this.voucherVos = voucherVos;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Double getAmount() {
        return amount;
    }

    public void setAmount(Double amount) {
        this.amount = amount;
    }

    public List<TransferVo> getTransferVos() {
        return transferVos;
    }

    public void setTransferVos(List<TransferVo> transferVos) {
        this.transferVos = transferVos;
    }

    public List<SumVo> getSumVos() {
        return sumVos;
    }

    public void setSumVos(List<SumVo> sumVos) {
        this.sumVos = sumVos;
    }
}
